<%
    layout("../head.html",{title:"扫码支付"}){
%>
<!--http://www.jq22.com/jquery-info294-->
<style>
    #qr{
        text-align: center;
        margin-top: 13%;
    }


</style>
    <body>
        <script type="text/javascript">
           $(function(){

               /*
               *获取支付宝二维码
               * */
               $.ajax({
                    type:'post',
                    url:'/api/pay/alipayTradePrecreate',
                    data:{
                        subject:'${alipayOrderEntity.subject!}',
                        outTradeNo:'${alipayOrderEntity.outTradeNo!}',
                        totalAmount:'${alipayOrderEntity.totalAmount!}',
                        storeId:'${alipayOrderEntity.storeId!}',
                        body:'${alipayOrderEntity.body!}',
                        notifyUrl:"${alipayOrderEntity.notifyUrl}",
                        returnUrl:'${alipayOrderEntity.returnUrl}'
                    },
                    dataType:'json',
                    success:function(data){
                        if(data.resultFlag){
                            $("#descript").prop("hidden",false);
                            $('#qr').qrcode({
                                background: "#FFF",
                                text: data.responseData
                            });
                        }else{
                            layerDef("二维码获取失败",{icon:5});
                        }
                    },
                   error:function(){
                       layerDef("请求异常",{icon:5});
                   }
                });

               /*
               * 定时查询支付接口，交易成功则跳转
               **/
               var interval =setInterval(function(){
                   $.ajax({
                       url: "/api/pay/queryAliPayStatus",
                       type: "post",
                       data:{
                           outTradeNo:'${alipayOrderEntity.outTradeNo!}'
                       },
                       dataType: "json",
                        success: function(data){
                           if(data.resultFlag&&data.responseData=='TRADE_SUCCESS'){
                                window.location.href="/Counselling/queryCounseModelAndView";
                           }
                       },
                       error:function(data){
                           lclearInterval(interval);
                       }
                   });
               },4000);
            });
        </script>
        <div id="qr" ></div>
        <p id="descript" hidden style="text-align: center;margin-top:6%">请扫描图中的二维码付款</p>
    </body>
<%}%>